<?php
class admin_report extends Admin_Controller
{
	public $menu_id = 8;
	public function __construct()
	{
		parent::__construct();
		$this->load->model('poll/poll_model','poll');
		$this->load->model('poll/polldetail_model','polldetail');
		$this->load->model('poll/pollresult_model','pollresult');
		$this->load->model('detail/suggess_detail_model','suggess_detail');
		$this->load->model('detail/suggess_result_model','suggess_result');
		$this->load->model('knowledge/knowledgefiles_model','knfile');
	}
	
	public function report_1()
	{
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');						
			$this->template->build('report_1',$data);
		}
		else{
			
			redirect('admin');	
		}
	}
	
	public function report_2(){
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');						
			$this->template->build('report_2',$data);
		}
		else{
			
			redirect('admin');	
		}
	}
	
	public function report_3(){
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');
			$this->template->build('report_3',$data);
		}
		else{
			
			redirect('admin');	
		}
	}
	
	public function report_4(){
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');
			
			if($_GET){
				if($_GET['month'] != '00'){
					$month1 = " AND MONTH(s1.created)=".$_GET['month'];
					$month2 = " 
AND MONTH(suggess_result.created)=".$_GET['month'];
				}
				if($_GET['type_id'] != 0){
					$type_id = " and tbknowledgetype.id = ".$_GET['type_id'];
				}
				
				$sql = "SELECT
suggess_result.created,
tbknowledgefiles.filename,
suggess_result.user_id,
suggess_result.ip,
tbknowledge.title as kntitle,
tbknowledgetype.title as kntypetitle,
tbknowledgefiles.id,
(SELECT COUNT(*)FROM suggess_result s1 WHERE s1.tbknowledgefile_id=tbknowledgefiles.id AND YEAR(s1.created)=".$_GET['start_year'].@$month1.")as download_count 
FROM
tbknowledgefiles
Left Join suggess_result ON tbknowledgefiles.id = suggess_result.tbknowledgefile_id
Left Join tbknowledge ON tbknowledgefiles.pid = tbknowledge.id
Left Join tbknowledgetype ON tbknowledge.knowledgetypeid = tbknowledgetype.id
where YEAR(suggess_result.created)=".$_GET['start_year'].@$month2.@$type_id." 
GROUP BY tbknowledgefiles.id";

				$data['knowledges'] = $this->knfile->get($sql);
			}
			
			$this->template->build('report_4',$data);
		}else{
			
			redirect('admin');	
		}
	}
	
	public function report_5(){
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');
			
			if($_GET){
				$condition = ($_GET['id'] != "")?"and id = ".$_GET['id']:"";
				$data['suggess_details'] = $this->suggess_detail->where("1=1 ".$condition)->get();
			}
								
			$this->template->build('report_5',$data);
		}else{
			redirect('admin');	
		}
	}
	
	public function report_6(){
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_section";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');
			
			if($_GET){
				
				$sql = "SELECT
						polls.id,
						polls.title,
						polls.active,
						polls.approve_id,
						polls.approve_date,
						polls.user_id,
						polls.created
						FROM
						polls
						WHERE
						year(polls.created) =  ".$_GET['start_year'];
				$data['polls'] = $this->poll->get($sql);
			}
			
			$this->template->build('report_6',$data);
		}else{
			redirect('admin');	
		}
	}
}
?>